import { Commit, Getter, GetterTree, Action, ActionTree, MutationTree } from 'vuex'
import axios from 'axios';
import {login,LoginIn } from '@/store/common/login'
import API from '@/api'



export interface State {
    loginList: login[],
   
}

const initState: State = {
    
    loginList:[],
}

const loginPost: Getter<State, any> = (state: State) => {
    return state.loginList
}





const loginAction: Action<State, any> = 
(context: { commit: Commit }) => {
    return new Promise((resolve, reject) => {
        axios({
            method: 'post',
            data:{
                userNameOrEmailAddress:"admin",
                password:"123qwe",
                rememberClient:true
            },
            url: API.TokenAuth.Authenticate
        }).then(function(res){
          console.log(res)
          context.commit('loginM', res);
        })
        .catch(function(err){
          console.log(err)
        }) 
    });
}



const mutations: MutationTree< State > = {
    
    loginM(state, list: login[]) {
        // state.loginList = list;
        // console.log("变化");
        console.log(state);
        console.log(list);
    },
    
    
};

const getters: GetterTree<State, any> = {
  
    loginPost,

   
};

const actions: ActionTree<State, any> = {
  
    loginAction
   
}

export default {
    namespaced: true,
    state: initState,
    getters,
    actions,
    mutations,
}